<%--
  Created by IntelliJ IDEA.
  User: argentum
  Date: 2018/12/31
  Time: 14:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <%@ include file="../../base/top.jsp" %>
    <title>作业列表</title>
</head>
<body class="no-skin">
<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <div class="hr hr-18 dotted hr-double"></div>
                <div class="row">
                    <div class="col-xs-12">
                        <%--data-table--%>
                        <div id="result_admin">
                            <table id="data-table" width="80%" style="margin-left: 10%" class="table table-striped table-bordered">
                                <thead>
                                <tr>
                                    <th>
                                        全选<input type="checkbox" id="check-all"/>
                                    </th>
                                    <th>作业名</th>
                                    <th>项目名</th>
                                    <th>格式</th>
                                    <th>上传日期</th>
                                    <th>任务</th>
                                    <th>阶段</th>
                                    <th>评阅状态</th>
                                </tr>
                                </thead>
                                <tbody>

                                </tbody>
                            </table>
                            <button type="button" class="btn btn-success" onclick="downloadAssignment()">下载</button>
                            <button type="button" class="btn btn-success" id="upload">上传</button>
                        </div>
                    </div>
                    <!-- /.col -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.page-content -->
        </div>
    </div>
    <!-- /.main-content -->
    <!-- 返回顶部 -->
    <form id="uploadForm">
        <input type="file" id="file" name="file"
               style="filter:alpha(opacity=0);opacity:0;width: 0;height: 0;"/>
    </form>
</div>
<!-- 页面底部js¨ -->
<%@ include file="../../base/foot.jsp" %>
<script>
    var table = null;
    var columnsData =  [
        {
            bSortable : false,
            className : "text-left",
            width : "50px",
            render : function(data, type, row, meta) {
                return "<input type=\"checkbox\"/>";
            }
        },
        {'data': 'assignmentName',
            render : function(data, type, row, meta) {
                return "<a style='cursor: pointer' onclick='showDetail(this)'>"+data+"</a>";
            }},
        {'data': 'projectName'},
        {'data': 'assignmentType'},
        {'data': 'assignmentUpdateTime', bSortable : false,
            render : function(data, type, row, meta) {
                if (data == null){
                    return  "";
                }
                return data;
            }},
        {'data': 'taskName',
            bSortable : false,
            render : function(data, type, row, meta) {
                if (data == null){
                    return  "";
                }
                return data;
            }},
        {'data': 'stageName', bSortable : false,
            render : function(data, type, row, meta) {
                if (data == null){
                    return  "";
                }
                return data;
            }},
        {'data': 'assignmentState',
            width : "50px",
            render : function(data, type, row, meta) {
                if(data==0){
                    return data = '未下载';
                }
                if(data==1){
                    return data = '未批阅';
                }
                if(data==2){
                    return data = '已批阅';
                }
            }
        },
    ];

    var url='assignment/showAllAssignment';
    var parameter ={
        teachCourseId:'20181208232425OL'
    };

    var dataBaseFiled =  [
        {
            data: null,
            bSortable : false,
            className : "text-left",
            width : "50px",
            render : function(data, type, row, meta) {
                return "<input type=\"checkbox\"/>";
            }
        },
        {'data': 'assignmentName'},
        {'data': 'projectName'},
        {'data': 'assignmentType'},
        {'data': 'assignmentUpdateTime'},
        {'data': 'taskName',
            bSortable : false,
            render : function(data, type, row, meta) {
                if (data == null){
                    return  "";
                }
                return data;
            }},
        {'data': 'stageName',
            bSortable : false,
            render : function(data, type, row, meta) {
                if (data == null){
                    return  "";
                }
                return data;
            }},
        {'data': 'assignmentState'}
    ];


    $(document).ready(function() {

        table = $('#data-table').DataTable($.extend(true,{},CONSTANT.DATA_TABLES.DEFAULT_OPTION,{

            columns:columnsData,

            ajax: function (data,callback) {
                ajax(data,callback,dataBaseFiled,url,parameter);
            }
        }));
    });

    function downloadAssignment() {
        var checked = getAllCheckedRowValue();
        var assignmentIds = new Array();
        for (var index = 0; index < checked.length; index++) {
            download(checked[index].assignmentName+"."+checked[index].assignmentType, checked[index].assignmentAddress);
            assignmentIds.push(checked[index].assignmentId);
            prompt_alert("info",checked[index].assignmentAddress);
        }
        $.ajax({
            type:"POST",
            url:"assignment/editAssignmentState",
            data:assignmentIds,
            processData:false,
            contentType:false,
            success:function (data) {
                if(data["success"]==true){
                    prompt_alert('success',"下载成功",0);
                    reloadDataTable();
                }else{
                    prompt_alert('error',"下载失败",0);
                }
            },
            error:function (){
                prompt_alert('error',"请检查网络连接...",0);
            },
        });
    }


    function showDetail(button) {
        var json =  getClickedRowValue(button);
        addTab('3','3','作业详情','assignment/view_assignment_details?'+parseParam(json));
    }

</script>

</body>
</html>
